;(function ($) {

    let page = GetQueryString("page") | 1;
    let limit = GetQueryString("limit") | 6;

    console.log(page, limit);

    $.ajax({
        url: "/api/agt_article/"+getId(),
        dataType: "json",
        async: false,
        success: function (result) {
            let div = $("#page-content");
            // console.log($("#page-title").find("span"));
            $("#page-title").find("span").text(result.articleTitle.substring(0, 10)+ "...");

            div.find(".Detail_newsConBox").append(`<div class="newsConBox_title">
                <h1>${result.articleTitle}</h1>
              </div>
              <div class="newsConBox_tips">
                <div class="newsConBox_tipsLeft">
                  <dl>
                    <dt>发布时间:</dt>
                    <dd>${result.createdTime}</dd>
                    <dt>作者:</dt>
                    <dd>${result.createdBy}</dd>
                    <!--<dt>阅读量:</dt>
                    <dd>192</dd>
                    <dt>评论数:</dt>
                    <dd>2</dd>
                    <dt>点赞数:</dt>
                    <dd>0</dd>-->
                  </dl>
                </div>
              </div>`);

            div.find(".Detail_summaryBox").append(`<div class="summaryBox_Con">
                <span>[&nbsp;摘要&nbsp;]</span>
                <span class="summaryBox_text">${result.articleAbstract}</span>
              </div>`);

            div.find(".Detail_officialBox").append(`<div class="officialBox_Con">
                ${result.articleContent}
              </div>`);
        }
    });

    //文章资讯
    $.ajax({
        url: "/api/agt_article/page",
        data: {
            page: 1,
            limit: 6
        },
        dataType: "json",
        async: false,
        success: function (result) {
            let div = $(".tabs_list").find(".info_Box");
            $.each(result.data, function (idx, obj) {
                let agtHtml = `<div class="info_con">
                    <div class="info_conLeft">
                      <a href="/article/${obj.id}">
                        <img src="${obj.articleCover}" alt="" width="86" height="86">
                      </a>
                    </div>
                    <div class="info_conRight">
                      <a href="/article/${obj.id}">
                        <p>${obj.articleAbstract}</p>
                      </a>
                    </div>
                  </div>`;
                div.append(agtHtml);
            });
        }
    });

    //农业百科
    $.ajax({
        url: "/api/agt_species/page",
        data: {
            page: 2,
            limit: 5
        },
        dataType: "json",
        async: false,
        success: function (result) {
            let div = $(".nowPro_Box").find("#nowPro_Con>ul");
            $.each(result.data, function (idx, obj) {
                let agtHtml = `<li><a href="/species/${obj.id}"><img style="width: 331px;height: 335px;" src="${obj.speciesCover}"></a></li>`;
                div.append(agtHtml);
            });
        }
    });



    function GetQueryString(name)
    {
        var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
        var r = window.location.search.substr(1).match(reg);
        if(r!=null)return  unescape(r[2]); return null;
    }

    function getContextPath() {
        let pathName = document.location.pathname;
        let index = pathName.substr(1).indexOf("/");
        let result = pathName.substr(0, index + 1);
        // console.log(pathName,index,result);
        return result;
    }

    function getId() {
        let pathName = document.location.pathname;
        let index = pathName.substr(1).lastIndexOf("/");
        let id = pathName.substr(index + 2);
        // console.log(pathName,index,id);
        return id;
    }
})(window.jQuery);